<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <textarea id="content"></textarea>
    <button id="btn">发送消息</button>
    <script>
      // 1. 连接上 web socket 服务器
      // const socket = new WebSocket("ws://localhost:8080");
      // const socket = new WebSocket("ws://127.0.0.1:8080");
      const socket = new WebSocket("ws://192.168.37.50:8080");

      // 2. 尝试向服务器发送消息
      document.getElementById("btn").onclick = () => {
        // 发送消息
        const content = document.getElementById("content").value;
        socket.send(content);
      };

      socket.onmessage = (e) => {
        console.log("客户端接受到的消息：", e.data);
      };
    </script>
  </body>
</html>
